package com.xiaoyu.client.ui.activity.login;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import com.xiaoyu.client.R;
import com.xiaoyu.client.ui.fragment.main.MainActivity;
import com.xiaoyu.commonlib.ui.base.BaseActivity;
import com.xiaoyu.commonlib.utils.PreferencesUtil;

import butterknife.ButterKnife;

/**
 * @author jx
 * @date 创建时间 2018/10/10
 * @Description 启动页
 */
public class SplashActivity extends BaseActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        ButterKnife.bind(this);
        hideOccupyView();
        initView();
    }

    private void initView() {
        if (PreferencesUtil.getBoolean(PreferencesUtil.KEY_HAS_GUIDED, false)) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    autoLogin();
                }
            }, 500);
        } else {
            gotoGuide();
        }
    }

    private void autoLogin() {
        final String token = PreferencesUtil.getString(PreferencesUtil.TOKEN, "");
        if (token.equals("")) {
            gotoLogin();
        } else {
            startActivity(new Intent(SplashActivity.this, MainActivity.class));
            finish();
        }
    }

    //跳转登录页
    private void gotoLogin() {
        Intent intent = new Intent(this, LoginActivity.class);
        if (getIntent().getExtras() != null) {
            intent.putExtras(getIntent().getExtras());
        }
        startActivity(intent);
        finish();
    }

    //跳转引导页
    private void gotoGuide() {
        Intent intent = new Intent(this, GuideActivity.class);
        startActivity(intent);
        finish();
    }
}